<template>
  <div class="account-settings-info-view">
    <a-row :gutter="16">
      <a-col :md="24" :lg="16">
        <a-spin :spinning="confirmLoading">
          <a-form :form="form" layout="vertical">
            <a-form-item
              label="系统名称"
            >
              <a-input placeholder="请输入系统名称" v-decorator="[ 'sysName', {}]"/>
            </a-form-item>

            <a-form-item
              label="系统版本"
            >
              <a-input placeholder="请输入系统版本" v-decorator="[ 'sysVersion', {}]" />
            </a-form-item>

            <a-form-item
              label="公司名称"
            >
              <a-input placeholder="请输入公司名称" v-decorator="[ 'orgName', {}]" />
            </a-form-item>

            <a-form-item
              label="版权信息"
            >
              <a-input placeholder="请输入版权信息" v-decorator="[ 'copyRight', {}]" />
            </a-form-item>

            <a-form-item
              label="公司简称"
            >
              <a-input placeholder="请输入公司简称" v-decorator="[ 'orgAbbr', {}]"/>
            </a-form-item>

            <a-form-item
              label="公司地址"
            >
              <a-input placeholder="请输入公司地址" v-decorator="[ 'orgAddr', {}]"/>
            </a-form-item>

            <a-form-item
              label="公司法人"
            >
              <a-input placeholder="请输入公司法人" v-decorator="[ 'corporation', {}]"/>
            </a-form-item>

            <a-form-item
              label="公司电话"
            >
              <a-input placeholder="请输入公司电话" v-decorator="[ 'orgTel', {}]"/>
            </a-form-item>

            <a-form-item
              label="公司邮箱"
            >
              <a-input placeholder="请输入公司邮箱" v-decorator="[ 'orgEmail', {}]"/>
            </a-form-item>

            <a-form-item
              label="系统描述"
            >
              <a-textarea rows="4" placeholder="请输入系统描述" v-decorator="[ 'description', {}]"/>
            </a-form-item>

            <a-form-item>
              <a-button type="primary" @click="handleSubmit" :disabled="confirmLoading">保存</a-button>
            </a-form-item>
          </a-form>
        </a-spin>
      </a-col>

    </a-row>

  </div>
</template>

<script>
  import pick from 'lodash.pick'
  import { getSysBaseInfo, changeSysBaseInfo } from '@api/api'

  export default {
    components: {

    },
    data () {
      return {
        confirmLoading: false,
        form: this.$form.createForm(this),
        model: {},
      }
    },
    created() {
      this.showData();
    },
    methods: {
      showData () {
        this.form.resetFields();
        getSysBaseInfo({id: 1}).then((res) => {
          if (res.success) {
            this.model = Object.assign({}, res.result)
          } else {
            this.$message.warn(res.message);
          }
        }).then(() => {
          this.$nextTick(() => {
            this.form.setFieldsValue(pick(this.model,
              'id', 'sysName', 'sysVersion', 'orgName', 'copyRight', 'orgAbbr',
              'orgAddr', 'corporation', 'orgTel', 'orgEmail', 'description'
            ));
          });
        });
      },
      handleSubmit(){
        this.form.validateFields((err, values) => {
          if (!err) {
            this.confirmLoading = true;
            let formData = Object.assign(this.model, values);
            changeSysBaseInfo(formData).then((res)=>{
              if(res.success){
                this.$message.success(res.message);
              }else{
                this.$message.warning(res.message);
              }
            }).finally(() => {
              this.confirmLoading = false;
              this.showData();
            });
          }
        });
      },
    }
  }
</script>

<style lang="less" scoped>

</style>